package com.day1;




import com.alibaba.fastjson.JSON;
import hk.JdbcUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/deluser")
public class DelUser extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //super.doGet(req, resp);
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        System.out.println("转页成功======");
        //获取参数
        int id = Integer.parseInt(req.getParameter("id"));
        System.out.println(id);

        //操作数据库
        try {
            //把获取的参数传给数据库进行操作
            int i = JdbcUtil.delUser(id);

            Map map=new HashMap();
            map.put("msg",i);

            String s = JSON.toJSONString(map);
            System.out.println(s);
            resp.getWriter().print(s);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}